package com.wolfcode.controller;

import com.wolfcode.pojo.Product;
import com.wolfcode.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author yinyin
 * @create 2022/08/19 下午 8:37
 */
@Controller
public class ProductController {

    @Autowired
    private ProductService productService;
    @GetMapping("/findAll")
    @ResponseBody
    public List<Product> findAll(){
        return productService.findAll();
    };
    @GetMapping("/findOne")
    @ResponseBody
    public Product findOne(){
        Long id=2L;
        return  productService.findOne(id);
    }
    @GetMapping("addProduct")
    @ResponseBody
    public void addProduct(){
        Product product = new Product();
        product.setName("gogogo");
        product.setDescription("双十一冲!");
        product.setCategoryName("双十一");
        product.setTags("购物节");
        product.setPrice(new BigDecimal(1999));
        product.setRealPrice(new BigDecimal(399));
        product.setStars(100000);
        product.setViews(399999999);
        productService.addProduct(product);
    }
    @GetMapping("updateProduct")
    @ResponseBody
    public void updateProduct(){
        Product product = new Product();
        product.setId(5L);
        product.setDescription("双十二冲");
        product.setCategoryName("双十二");
        product.setPrice(new BigDecimal(5999));
        product.setRealPrice(new BigDecimal(599));
        product.setStars(500000);
        product.setViews(555555);
        productService.updateProduct(product);
    }
    @GetMapping("deleteProduct")
    @ResponseBody
    public void  deleteProduct(){
        productService.deleteProduct(4L);
    }

}
